from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-07-11 14:13:51.286486
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 11, Jul, 2022
Time: 14:13:57
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.7637
Nobs: 714.000 HQIC: -50.1173
Log likelihood: 8943.22 FPE: 1.37309e-22
AIC: -50.3398 Det(Omega_mle): 1.21153e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298381 0.057273 5.210 0.000
L1.Burgenland 0.104506 0.037599 2.780 0.005
L1.Kärnten -0.109466 0.019935 -5.491 0.000
L1.Niederösterreich 0.210336 0.078625 2.675 0.007
L1.Oberösterreich 0.105681 0.076917 1.374 0.169
L1.Salzburg 0.257087 0.040248 6.388 0.000
L1.Steiermark 0.044740 0.052417 0.854 0.393
L1.Tirol 0.109699 0.042560 2.577 0.010
L1.Vorarlberg -0.061167 0.036812 -1.662 0.097
L1.Wien 0.045597 0.067879 0.672 0.502
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.047436 0.119890 0.396 0.692
L1.Burgenland -0.034309 0.078706 -0.436 0.663
L1.Kärnten 0.041194 0.041731 0.987 0.324
L1.Niederösterreich -0.167172 0.164586 -1.016 0.310
L1.Oberösterreich 0.422414 0.161011 2.624 0.009
L1.Salzburg 0.288268 0.084252 3.421 0.001
L1.Steiermark 0.100535 0.109724 0.916 0.360
L1.Tirol 0.318657 0.089092 3.577 0.000
L1.Vorarlberg 0.027323 0.077059 0.355 0.723
L1.Wien -0.037051 0.142091 -0.261 0.794
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187729 0.029336 6.399 0.000
L1.Burgenland 0.089332 0.019259 4.639 0.000
L1.Kärnten -0.007941 0.010211 -0.778 0.437
L1.Niederösterreich 0.264729 0.040273 6.573 0.000
L1.Oberösterreich 0.137392 0.039398 3.487 0.000
L1.Salzburg 0.046044 0.020616 2.233 0.026
L1.Steiermark 0.020038 0.026849 0.746 0.455
L1.Tirol 0.091414 0.021800 4.193 0.000
L1.Vorarlberg 0.057459 0.018856 3.047 0.002
L1.Wien 0.114947 0.034769 3.306 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111746 0.029804 3.749 0.000
L1.Burgenland 0.045160 0.019566 2.308 0.021
L1.Kärnten -0.013787 0.010374 -1.329 0.184
L1.Niederösterreich 0.191087 0.040915 4.670 0.000
L1.Oberösterreich 0.303278 0.040026 7.577 0.000
L1.Salzburg 0.108326 0.020945 5.172 0.000
L1.Steiermark 0.104712 0.027277 3.839 0.000
L1.Tirol 0.104105 0.022148 4.700 0.000
L1.Vorarlberg 0.066556 0.019156 3.474 0.001
L1.Wien -0.021814 0.035323 -0.618 0.537
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.134478 0.054353 2.474 0.013
L1.Burgenland -0.052042 0.035682 -1.459 0.145
L1.Kärnten -0.044381 0.018919 -2.346 0.019
L1.Niederösterreich 0.155813 0.074616 2.088 0.037
L1.Oberösterreich 0.139800 0.072996 1.915 0.055
L1.Salzburg 0.286797 0.038196 7.508 0.000
L1.Steiermark 0.047688 0.049744 0.959 0.338
L1.Tirol 0.167196 0.040391 4.139 0.000
L1.Vorarlberg 0.092044 0.034935 2.635 0.008
L1.Wien 0.074931 0.064418 1.163 0.245
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055023 0.043247 1.272 0.203
L1.Burgenland 0.037911 0.028391 1.335 0.182
L1.Kärnten 0.050924 0.015053 3.383 0.001
L1.Niederösterreich 0.217014 0.059370 3.655 0.000
L1.Oberösterreich 0.295015 0.058081 5.079 0.000
L1.Salzburg 0.047981 0.030392 1.579 0.114
L1.Steiermark 0.001463 0.039580 0.037 0.971
L1.Tirol 0.141391 0.032138 4.400 0.000
L1.Vorarlberg 0.072662 0.027797 2.614 0.009
L1.Wien 0.081489 0.051256 1.590 0.112
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174515 0.051720 3.374 0.001
L1.Burgenland -0.002977 0.033953 -0.088 0.930
L1.Kärnten -0.062996 0.018002 -3.499 0.000
L1.Niederösterreich -0.081247 0.071001 -1.144 0.252
L1.Oberösterreich 0.193795 0.069459 2.790 0.005
L1.Salzburg 0.056613 0.036346 1.558 0.119
L1.Steiermark 0.235705 0.047334 4.980 0.000
L1.Tirol 0.497607 0.038434 12.947 0.000
L1.Vorarlberg 0.043589 0.033243 1.311 0.190
L1.Wien -0.052144 0.061297 -0.851 0.395
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170718 0.059005 2.893 0.004
L1.Burgenland -0.010433 0.038736 -0.269 0.788
L1.Kärnten 0.063562 0.020538 3.095 0.002
L1.Niederösterreich 0.205659 0.081003 2.539 0.011
L1.Oberösterreich -0.074866 0.079243 -0.945 0.345
L1.Salzburg 0.213160 0.041465 5.141 0.000
L1.Steiermark 0.125743 0.054002 2.328 0.020
L1.Tirol 0.068899 0.043848 1.571 0.116
L1.Vorarlberg 0.118496 0.037925 3.124 0.002
L1.Wien 0.121515 0.069931 1.738 0.082
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.362375 0.034183 10.601 0.000
L1.Burgenland 0.006371 0.022441 0.284 0.776
L1.Kärnten -0.023478 0.011898 -1.973 0.048
L1.Niederösterreich 0.216825 0.046927 4.620 0.000
L1.Oberösterreich 0.201888 0.045908 4.398 0.000
L1.Salzburg 0.043267 0.024022 1.801 0.072
L1.Steiermark -0.015073 0.031285 -0.482 0.630
L1.Tirol 0.104939 0.025402 4.131 0.000
L1.Vorarlberg 0.069897 0.021971 3.181 0.001
L1.Wien 0.035088 0.040513 0.866 0.386
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037421 0.139062 0.194613 0.155953 0.115325 0.102778 0.057491 0.217248
Kärnten 0.037421 1.000000 -0.015415 0.134171 0.056021 0.095115 0.435682 -0.053556 0.093704
Niederösterreich 0.139062 -0.015415 1.000000 0.335394 0.141434 0.294081 0.093282 0.176182 0.313558
Oberösterreich 0.194613 0.134171 0.335394 1.000000 0.227349 0.325312 0.176702 0.164649 0.262185
Salzburg 0.155953 0.056021 0.141434 0.227349 1.000000 0.138333 0.117067 0.138489 0.129298
Steiermark 0.115325 0.095115 0.294081 0.325312 0.138333 1.000000 0.145750 0.131940 0.071023
Tirol 0.102778 0.435682 0.093282 0.176702 0.117067 0.145750 1.000000 0.110833 0.142858
Vorarlberg 0.057491 -0.053556 0.176182 0.164649 0.138489 0.131940 0.110833 1.000000 -0.001405
Wien 0.217248 0.093704 0.313558 0.262185 0.129298 0.071023 0.142858 -0.001405 1.000000